package com.atguigu.gmall.web.controller;

import com.atguigu.gmall.model.product.SkuInfo;
import com.atguigu.gmall.product.client.ProductFeignClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;

import javax.servlet.http.HttpServletRequest;

/**
 * @Author atguigu-mqx
 * @Description TODO
 * @Date 2023/9/1 9:27
 * @Version 1.0
 */
@Controller
public class CartController {

    @Autowired
    private ProductFeignClient productFeignClient;
    //  添加购物车控制器 window.location.href = 'http://cart.gmall.com/addCart.html?skuId=' + this.skuId + '&skuNum=' + this.skuNum

    /**
     * 添加购物车控制器
     * @param request
     * @return
     */
    @GetMapping("addCart.html")
    public String addCart(HttpServletRequest request){
        //  存储skuInfo;
        SkuInfo skuInfo = productFeignClient.getSkuInfo(Long.parseLong(request.getParameter("skuId")));
        request.setAttribute("skuInfo",skuInfo);
        //  存储购买数量.
        request.setAttribute("skuNum",request.getParameter("skuNum"));
        //  返回添加成功页面
        return "cart/addCart";
    }

    /**
     * 查看购物车列表
     * @return
     */
    @GetMapping("cart.html")
    public String cartList(){
        //  返回购物车列表页面
        return "cart/index";
    }


}
